const { createBiTree,createBitreeByLevelOrder } =  require("./createBitree");

const biTree = createBiTree(10);

/**
 * 
 * @param {biTree} root 
 * @description 中序遍历递归实现
 * @returns 
 */
function inOrderByRecursion(root) {
    if(root === null) {
        return;
    }
    inOrderByRecursion(root.left);
    console.log(root.value);
    inOrderByRecursion(root.right);
}



/**
 * 
 * @param {biTree} root 
 */
function inOrderByNoRecursion(root) {
    const stack = [];
    let temp = root;

    while(stack.length !== 0 || temp !== null) {

        if(temp !== null) {

            stack.push(temp);
            temp = temp.left;
        }else {

            temp = stack.pop();
            console.log(temp.value);
            temp = temp.right;
        }
    }
}


inOrderByRecursion(biTree);
console.log('=======');
inOrderByNoRecursion(biTree);